import java.text.DecimalFormat;

import processing.core.PApplet;

/**
 *Creates a circle object that represents a single transaction of voice, text, or data type
 * @author Kevin Wong
 *
 */
public class Node {
	private PApplet 	p;
	private float		x;
	private float		y;
	private int 		diameter;
	
	private String 		type;
	private String		date;
	
	private int color;
	private int selectColor = 0xA0FF8C00;
	
	DecimalFormat df;

	public Node(PApplet parent, float xPosition, float yPosition, int duration, String usageType, String usageDate, int sColor) {
		p 			= parent;
		x 			= xPosition;
		y 			= yPosition;
		diameter 	= duration;
		type 		= usageType;
		date 		= usageDate;
		color 		= sColor;
	
		df = new DecimalFormat();
		df.setMinimumFractionDigits(2);
	}


	public void draw() {
		p.smooth();
		p.noStroke();
		p.fill(color);
		//p.ellipse(x,y,diameter,diameter);
		p.ellipse(x,y,10,10);
	}
	
	public int getColor() {
		return color;
	}
	
	public String getType () {
		return type;
	}
	
	public float getDiameter() {
		return diameter;
	}
	
	public String getDate() {
		return date;
	}
	
	public float getX() {
		return x;
	}

	public float getY() {
		return y;
	}
	
	public void setX(float f) {
		x = f;
	}
	
	public void setY(float f) {
		y = f;
	}
	
	@SuppressWarnings("static-access")
	public void mouseOver() {
		float disX = x - p.mouseX;
		float disY = y - p.mouseY;

		if ((p.sqrt(p.sq(disX) + p.sq(disY)) < diameter/2)) {
			drawHoverCircle();
		}
	}
	
	public void drawHoverCircle() {
		float textX = x;
		float textY = y;
		
		p.fill(selectColor);
		p.ellipse(x,y,diameter+5,diameter+5);
		p.fill(255);
		p.textSize(15);
		p.textAlign(p.RIGHT);
		
		if (p.mouseX < textX || p.mouseY < textY) {
			p.textAlign(p.LEFT);
			textX += 10;
			textY += 10;
		} else {
			textX -= 10;
			textY -= 10;
		}
		p.text(date,textX,textY);
		if (type.equals("Text messages"))
			p.text(diameter/10,textX,textY+12);
		else if (type.equals("Data"))
			p.text(diameter + "MB",textX,textY+12);
		else 
			p.text(diameter + " Min",textX,textY+12);
	}
}
